#include <iostream>
using namespace std;

class Product
{
public:
    Product(string name, int price, int quantity)
    {
        this->productName = name;
        this->price = price;
        this->quantity = quantity;
    }
    ~Product()
    {
        cout << "析构函数被调用" << endl;   
    }
    void show()
    {
        cout << "商品名称：" << productName << endl;
        cout << "商品价格：" << price << endl;
        cout << "商品数量：" << quantity << endl;
    }
    void buy(int num)
    {
        cout << "购买商品数量：" << num << endl;
        this->quantity -= num;
    }
private:
    string productName;
    int price;
    int quantity;

};


int main()
{
    Product *p = new Product("电脑", 5000, 10);
    p->show();
    p->buy(5);
    p->show();
    delete p;


    return 0;
}